import Page
from Page import Manual
from Base.Base import Base
from selenium.webdriver.common.by import By


class ManualIndexPage(Base):
    """
    使用手册首页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.manual_home_btn = (By.XPATH, Manual.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.manual_back_btn = (By.XPATH, Manual.RESOURCE_ID.format('ivBack'))

        # 应用标题
        self.manual_app_title_text = (By.XPATH, Manual.app_use_title_text.format(""))

        # 应用图片
        self.manual_use_cover_img = (By.XPATH, Manual.app_use_cover_img.format(""))

        # 应用介绍
        self.manual_use_introduction_text = (By.XPATH, Manual.app_use_introduction_text.format(""))

        # 查看详情按钮
        self.manual_use_see_details_btn = (By.XPATH, Manual.app_use_see_details_text.format(""))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.manual_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.manual_back_btn)

    def get_app_title(self, index=1):
        """
        获取app名称

        index 获取列表的序号,默认为1
        :return:获取元素
        """
        self.manual_app_title_text = (By.XPATH, Manual.app_use_title_text.format(index))
        return self.find_element_o(self.manual_app_title_text)

    def get_use_cover(self, index=1):
        """
        获取app图片

        index 获取列表的序号,默认为1
        :return:获取元素
        """
        self.manual_use_cover_img = (By.XPATH, Manual.app_use_cover_img.format(index))
        return self.find_element_o(self.manual_use_cover_img)

    def get_use_introduction(self, index=1):
        """
        获取app介绍

        index 获取列表的序号,默认为1
        :return:获取元素
        """
        self.manual_use_introduction_text = (By.XPATH, Manual.app_use_introduction_text.format(index))
        return self.find_element_o(self.manual_use_introduction_text)

    def click_use_see_details(self, index=1):
        """
        点击查看详情按钮

        :return:None
        """
        self.manual_use_see_details_btn = (By.XPATH, Manual.app_use_see_details_text.format(index))
        self.click_element(self.manual_use_see_details_btn)

    def swipe_manual_index(self):
        """
        滑动使用手册列表

        :return:None
        """
        self.swipe_o(location=(350, 1600, 277, 277), direction='left')

    def is_display_manual_index(self):
        """
        查看是否进入玩转delife首页

        :return:
        """
        self.manual_use_see_details_btn = (By.XPATH, Manual.app_use_see_details_text.format(1))
        return self.is_display(self.manual_use_see_details_btn)
